package com.baidu.day02;

public class Demo04 {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        int result = m1(arr);
        System.out.println(result);
        double pj = m2(arr);
        System.out.println(pj);
        int max = m3(arr);
        System.out.println(max);
        int min = m4(arr);
        System.out.println(min);

    }

    //这个是和
    public static int m1(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }


    //这个是平均值
    public static double m2(int[] arr) {
        double arg = m1(arr) / arr.length;
        return arg;


    }

    //这个是最大值
    public static int m3(int[] arr) {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }

        }
        return max;
    }

    //这个 是最小值
    public static int m4(int[] arr) {
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (min > arr[i]) {
                min = arr[i];
            }

        }
        return min;
    }
}


